﻿namespace MyCalendarHomework
{
    internal class Program
    {
        const int monthWidth = 35;
        const int monthHeight = 10;
        /// <summary>
        /// 2022年日历
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //初始光标
            int x = 0, y = 0;
            DateTime theDay = new DateTime(2022, 1, 1);
            //使用do循环实现日历
            do
            {
                //每月1日
                if ((int)theDay.Day == 1)
                {
                    //初始化位置
                    x = ((theDay.Month - 1) % 3) * monthWidth;
                    y = (theDay.Month - 1) / 3 * monthHeight;
                    //打印月份
                    Console.SetCursorPosition(x, y);
                    Console.Write(theDay.Month + "月");
                    y = y + 1;
                    Console.SetCursorPosition(x, y);
                    Console.Write("  日  一  二  三  四  五  六");
                    y = y + 1;
                    //打印每月1日
                    x = (int)(theDay.DayOfWeek) * 4 + x;
                    Console.SetCursorPosition(x, y);
                    Console.Write("1".PadLeft(4, ' '));

                }
                //打印星期六特殊位置
                if ((int)theDay.DayOfWeek == 6)
                {
                    //星期六如果不是1日
                    if ((int)theDay.Day != 1)
                    {
                        Console.Write(theDay.Day.ToString().PadLeft(4, ' '));
                    }
                    //换行并输出
                    x = x - 24;
                    Console.SetCursorPosition(x, y + 1);
                    y += 1;
                }
                //其它日期的输出
                else
                {
                    if ((int)theDay.Day != 1)
                    { Console.Write(theDay.Day.ToString().PadLeft(4, ' ')); }
                    x += 4;
                }
                theDay = theDay.AddDays(1);
            } while (theDay.Year == 2022);

        }
    }
}